#include <iostream>
using namespace std;
#include <iomanip>
using std::setw;
#include <cmath>
#include <cstring>
#include<list>
#include<vector>

double find_lastkongge(string Str)
{
	string::iterator iter;
	double i=0;
	int key=0;
	for (iter= Str.end();  iter>= Str.begin(); --iter) 
    {
    	if(*iter==' ')
    	{
    		key=1;
			break; 
		}
		i++;
    }
    if(key==0) return 0.1;
    if(key==1) return Str.length()-i;
}

int count_Alp(string Str1)
{
	string::iterator iter;
	iter=Str1.end()-1;
	char a=*iter;
	string Str2;
	int cont=0;
	double loc=find_lastkongge(Str1);
	if (loc!=0.1)
	{
		Str2=Str1.substr(0,loc);
		for (iter= Str2.begin();  iter!= Str2.end(); ++iter)
		{
			if(*iter==a) cont++;
		 } 
	}
	return cont;
}

int main()
{
	string Str1="AAAABCDEF A";
	int cont;
	cont=count_Alp(Str1);
	cout << cont;
	return 0;
}
